<template>
	<view class="userLayout jbBG" v-if="userInfo">
		<view :style="{height:getNavBarHeight()+'px'}"></view>
		<view class="userInfo">
			<view class="avator">
				<image src="/static/images/xxmLogo.png" mode="aspectFill"></image>
			</view>
			<view class="ip">
				{{userInfo.IP || '未知IP'}}
			</view>
			<view class="address">
				来自{{ userInfo.address.city || userInfo.address.province || userInfo.address.country}}
			</view>
		</view>

		<view class="section" >
			<view class="list">
				<view class="row" @click="onNavigator('download')">
					<view class="left">
						<uni-icons type="folder-add-filled" size="20" color="#34cfc2"></uni-icons>
						<view class="text">
							我的下载
						</view>
					</view>
					<view class="right">
						<view class="text">
							{{userInfo.downloadSize}}
						</view>
						<uni-icons type="right" size="15" color="$#aaa"></uni-icons>
					</view>
				</view>

				<view class="row" @click="onNavigator('score')">
					<view class="left">
						<uni-icons type="folder-add-filled" size="20" color="#34cfc2"></uni-icons>
						<view class="text">
							我的评分
						</view>
					</view>
					<view class="right">
						<view class="text">
							{{userInfo.scoreSize}}
						</view>
						<uni-icons type="right" size="15" color="$#aaa"></uni-icons>
					</view>
				</view>

				<view class="row">
					<view class="left">
						<uni-icons type="folder-add-filled" size="20" color="#34cfc2"></uni-icons>
						<view class="text">
							联系客服
						</view>
					</view>
					<view class="right">
						<!-- <view class="text">
							33
						</view> -->
						<uni-icons type="right" size="15" color="$#aaa"></uni-icons>
					</view>
					<!-- #ifdef MP -->
					<button open-type="contact">联系客服</button>
					<!-- #endif -->
					<!-- #ifndef MP -->
					<button open-type="contact" @click="Call">拨打电话</button>
					<!-- #endif -->

				</view>

			</view>
		</view>
		<view class="section">
			<view class="list">
				<view class="row" @click="onGo('geng')">
					<view class="left">
						<uni-icons type="folder-add-filled" size="20" color="#34cfc2"></uni-icons>
						<view class="text">
							订阅更新
						</view>
					</view>
					<view class="right">
						<uni-icons type="right" size="15" color="$#aaa"></uni-icons>
					</view>
				</view>
				<view class="row" @click="onGo('wen')">
					<view class="left">
						<uni-icons type="folder-add-filled" size="20" color="#34cfc2"></uni-icons>
						<view class="text">
							常见问题
						</view>
					</view>
					<view class="right">
						<uni-icons type="right" size="15" color="$#aaa"></uni-icons>
					</view>
				</view>
			</view>
		</view>
	</view>
	
	<view class="loading">
		<uni-load-more status="loading"></uni-load-more>
	</view>
</template>

<script setup>
	import { ref } from 'vue';
	import {onLoad} from '@dcloudio/uni-app';
import { getNavBarHeight } from '@/utils/system.js';
import { getUserInfoApi } from '@/api/api.js'
	
	/* ========常用变量================= */
	const userInfo = ref();
	/* 下载评分跳转 */
	function onNavigator(type) {
		let name = type === 'download' ? '我的下载' : '我的评分';
		uni.navigateTo({
			url:`/pages/classlist/classlist?name=${name}&type=${type}`
		})
	}
	function Call() {
		uni.makePhoneCall({
			phoneNumber: "15697403239",
			success() {
				console.log("拨打电话")
			}
		})
	}
	/* 常见问题 和 订阅更新 跳转*/
	const onGo = (type) => {
		let id;
		if (type === "geng" ) {
			id = '653507c6466d417a3718e94b'
		}else {
			id = '6536358ce0ec19c8d67fbe82'
		}
		uni.navigateTo({
			url:`/pages/notice/detail?id=${id}`
		})
	}
	/* 获取用户信息 */
	const getUserInfo = () => {
		getUserInfoApi().then(res => {
			console.log(res);
			userInfo.value = res.data;
		})
	}
	onLoad(() => {
		getUserInfo();
	})
</script>

<style lang="scss" scoped>
	.userLayout {
		.userInfo {
			/* 居中操作 */
			display: flex;
			justify-content: center;
			align-items: center;
			flex-direction: column;
			padding: 50rpx 0;

			.avator {
				width: 160rpx;
				height: 160rpx;
				border-radius: 50%;
				overflow: hidden;

				image {
					width: 100%;
					height: 100%;
				}
			}

			.ip {
				padding: 20rpx 0 5rpx;
				color: #333;
				font-size: 44rpx;
			}

			.address {
				font-size: 28rpx;
				color: #bebfc1;
			}
		}

		.section {
			width: 690rpx;
			margin: 50rpx auto;
			border: 1px solid #eee;
			border-radius: 10rpx;
			box-shadow: 0 0 30rpx rgba(0, 0, 0, 0.1);

			.list {
				.row {
					display: flex;
					flex-direction: row;
					justify-content: space-between;
					align-items: center;
					padding: 0 30rpx;
					height: 100rpx;
					border-bottom: 1px solid #eee;
					position: relative;

					&:last-child {
						border-bottom: none;
					}

					.left {
						display: flex;
						align-items: center;

						.text {
							margin-left: 10rpx;
							color: #666;
						}
					}

					.right {
						display: flex;
						align-items: center;

						.text {
							font-size: 28rpx;
							color: #aaa;
						}
					}

					button {
						position: absolute;
						top: 0;
						left: 0;
						height: 100rpx;
						width: 100%;
						opacity: 0;
					}
				}
			}
		}
	}
</style>